<template>
  <div class="mainMenu">
    <div class="logo">
      <img class="img" src="@/assets/img/logo.svg" />
      <h2 class="title">二货管理系统</h2>
    </div>
    <div class="menu">
      <el-menu
        text-color="#b7bdc3"
        active-text-color="#fff"
        background-color="#001529"
        :collapse="iscollapse"
        :router="true"
        :default-active="$route.path"
      >
        <template v-for="item in userMenuTree" :key="item.id">
          <el-sub-menu :index="String(item.id)">
            <template #title>
              <!-- 使用动态组件添加文字图标 -->
              <el-icon><component :is="item.icon.split('el-icon')[1]"></component></el-icon>

              <span>{{ item.name }}</span>
            </template>

            <template v-for="childItem in item.children" :key="childItem.id">
              <el-menu-item :index="childItem.url">
                <span>{{ childItem.name }}</span>
              </el-menu-item>
            </template>
          </el-sub-menu>
        </template>
      </el-menu>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps } from 'vue'

import { useLoginStore } from '@/store/login/login'

const props = defineProps({
  iscollapse: {
    type: Boolean,
    default: false
  }
})
const loginStore = useLoginStore()
const userMenuTree = loginStore.userMenuTree
</script>

<style lang="scss" scoped>
.mainMenu {
  height: 100vh;
  background-color: #001529;
  .logo {
    display: flex;
    height: 28px;
    padding: 12px 10px 8px 10px;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    box-sizing: content-box;

    .img {
      height: 30px;
      margin: 0 10px;
    }
    .title {
      color: white;
      font-size: 1rem;
      white-space: nowrap;
      font-weight: 700;
    }
  }
  .menu {
    width: 100%;
  }
}

.el-menu {
  border-right: none;
  user-select: none;
  transition: width 0.3s ease;
}

.el-sub-menu {
  .el-menu-item {
    padding-left: 50px !important;
    background-color: #0c2135;
  }
  .el-menu-item:hover {
    color: #fff;
  }
  .el-menu-item.is-active {
    background-color: #0a60bd;
  }
  span {
    padding-left: 20px;
  }
}
</style>
